package com.aop;

import com.aop.cglib.aop.EatProxy;
import com.aop.jdk.aop.Child;
import com.aop.jdk.aop.Eat;
import com.aop.jdk.aop.ProxyHandleImpl;
import com.aop.springaop.aspectj.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.annotation.PostConstruct;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

@SpringBootApplication
public class AopDemoApplication {
    @Autowired
    private LoginService loginService1;
    private static LoginService loginService;
    @PostConstruct
    public void setLoginService(){
        loginService = loginService1;
    }
	public static void main(String[] args) {
		SpringApplication.run(AopDemoApplication.class, args);

        System.out.println("======================JDk aop start======================");
		Eat eat = new Child();

		ClassLoader classLoader = eat.getClass().getClassLoader();
		Class<?>[] interfaces = eat.getClass().getInterfaces();
		Method[] methods = eat.getClass().getMethods();

		ProxyHandleImpl proxyHandle = new ProxyHandleImpl(eat);

		Eat subject = (Eat) Proxy.newProxyInstance(classLoader, interfaces, proxyHandle);
		subject.eat();

        System.out.println("\n\n\n======================cglib aop start======================");

        com.aop.cglib.aop.Eat eatCglib = (com.aop.cglib.aop.Eat)new EatProxy().getProxy(com.aop.cglib.aop.Eat.class);
        eatCglib.eat();

        System.out.println("\n\n\n===================spring aop aspectj start===================");
        loginService.login("jack");
    }
}
